<template>
	<view class="container">
		<u-toast ref="uToast" />
		<u-navbar :is-back="true" :title="toggle_title" back-icon-color='#333333' height="50" :border-bottom="false">
		</u-navbar>
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirm"></u-picker>
		<view class="list">
			<view class="designation">
				<text>名称</text>
				<text>{{conference_name}}</text>
			</view>
			<view class="numeration">
				<text>ID</text>
				<text>{{conference_id}}</text>
			</view>
			<view class="address">
				<text>地点</text>
				<text>{{conference_address}}</text>
			</view>
			<view class="type">
				<text>类型</text>
				<text>{{conference_type}}</text>
			</view>
			<view class="galleryful">
				<text>容纳人数</text>
				<text>{{conference_people}}</text>
			</view>
			<view class="remarks">
				<text>备注</text>
				<u-input v-model="form.remark" style="margin-left:150rpx; width: 200rpx;" :type="type"
					placeholder="单行输入" :border="border" input-align="right" />
			</view>
			<view class="time">
				<view class="top">
					<text>使用时间</text>
					<text>{{startDate}}&nbsp;{{startTime}}</text>
					<image src="../../static/tupian105.png" mode="widthFix" @click="calendar(1)"></image>
				</view>
				<view class="bottom">
					<text>{{endDate}}&nbsp;{{endTime}}</text>
					<image src="../../static/tupian105.png" mode="widthFix" @click="calendar(2)"></image>
				</view>
			</view>
			<view class="event">
				<text>事件</text>
				<u-input v-model="form.event" style="margin-left:200rpx; width: 200rpx;" :type="type" placeholder="单行输入"
					:border="border" input-align="right" />
			</view>
		</view>
		<view class="confirm">
			<view class="verify" @click="apply">
				{{verify}}
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../request.js'
	import time from '../../time.js'
	export default {
		data() {
			return {
				type: 'text',
				border: false,
				content: '',
				show: false,
				num: '',
				startDate: '',
				startTime: '',
				endDate: '',
				endTime: '',
				form: {
					meeting_room_id: '',
					start_time: '',
					end_time: '',
					event: '',
					handle_user_id: 0,
					remark: '',
				},
				edit_form: {
					meeting_room_id: '',
					start_time: '',
					end_time: '',
					event: '',
					handle_user_id: 0,
					apply_id: '',
				},
				conference_name: '',
				conference_id: '',
				conference_address: '',
				conference_type: '',
				conference_people: '',
				remarks_content: '',
				license_content: '',
				event_content: '',
				boolen: false,
				toggle_title: '',
				verify: '提交',
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				meeting_id: '',

			}
		},
		onLoad(options) {
			console.log(options);
			if (options) {
				let {
					meeting_id,
					name,
					genre,
					people,
					site,
					meeting_remark
				} = options;
				this.conference_name = name;
				this.conference_id = meeting_id;
				this.conference_address = site;
				this.conference_type = genre;
				this.conference_people = people;
				this.form.meeting_room_id = meeting_id;
				this.form.remark = meeting_remark;
			}
			if (options.id) {
				this.toggle_title = '修改申请';
				this.meeting_id = options.id;
				this.applyDetail();
			} else {
				this.toggle_title = '发起申请';
			}
		},
		methods: {
			apply() {
				let base_url = uni.getStorageSync('host');
				console.log(base_url);
				let _this = this;
				if (this.toggle_title=='发起申请') {
					request({
						url: base_url + 'teacher/meeting_room/apply',
						method: 'post',
						data: {
							...this.form
						},
						success(res) {
							if (res.statusCode == 200) {
								console.log(res.data);
								_this.$toLink('../function_room/function_room', {
									function_id: 1
								})
							} else {
								_this.$refs.uToast.show({
									title: res.data.message || '系统错误',
									type: 'warning',
								})
							}

						}
					})
				} else {
					this.edit_form.event = this.form.event;
					request({
						url: base_url + 'teacher/meeting_room/applyChange',
						method: 'post',
						data: {
							...this.edit_form,
						},
						success(res) {
							if (res.statusCode == 200) {
								console.log(res.data);
								_this.$toLink('../function_room/function_room', {
									function_id: 1
								})
							} else {
								_this.$refs.uToast.show({
									title: res.data.message || '系统错误',
									type: 'warning',
								})
							}

						}
					})
				}

			},
			applyDetail() {
				let _this = this;
				let base_url = uni.getStorageSync('host');
				request({
					url: base_url + 'teacher/meeting_room/applyDetail',
					method: 'post',
					data: {
						apply_id: this.meeting_id ? this.meeting_id : 14,
					},
					success(res) {
						if (res.statusCode == 200) {
							let obj = {};
							console.log(res.data.data);
							obj = res.data.data;
							_this.conference_name = obj.meeting_room_detail.name;
							_this.conference_id = obj.meeting_room_detail.meeting_room_id;
							_this.conference_address = obj.meeting_room_detail.place;
							_this.conference_type = obj.meeting_room_detail.type;
							_this.conference_people = obj.meeting_room_detail.people;
							_this.edit_form.meeting_room_id = obj.meeting_room_detail.meeting_room_id;
							_this.form.remark = obj.meeting_room_detail.remark;
							_this.edit_form.apply_id = obj.apply_id;
							_this.edit_form.handle_user_id = obj.handle_user_id;
							_this.edit_form.event = obj.event;
							_this.edit_form.start_time = obj.start_time;
							_this.edit_form.end_time = obj.end_time;
							_this.form.event = obj.event;
							_this.startDate = obj.start_time;
							_this.endDate = obj.end_time;
						} else {
							_this.$refs.uToast.show({
								title: res.data.message || '系统错误',
								type: 'warning',
							})
						}

					}
				})
			},
			confirm(e) { //对时间的格式进行处理
				let str = '';
				console.log(e);
				switch (this.num) {
					case 1:

						this.startDate = `${e.year}.${e.month}.${e.day}`
						this.startTime = `${e.hour}:${e.minute}:${e.second}`
						if (this.toggle_title == '修改申请') {
							this.edit_form.start_time = `${e.year}-${e.month}-${e.day}-${e.hour}:${e.minute}:${e.second}`;
						} else {
							this.form.start_time = `${e.year}-${e.month}-${e.day}-${e.hour}:${e.minute}:${e.second}`;
						}
						break;
					case 2:
						this.endDate = `${e.year}.${e.month}.${e.day}`
						this.endTime = `${e.hour}:${e.minute}:${e.second}`
						if (this.toggle_title == '修改申请') {
							this.edit_form.end_time = `${e.year}-${e.month}-${e.day}-${e.hour}:${e.minute}:${e.second}`;
						} else {
							this.form.end_time = `${e.year}-${e.month}-${e.day}-${e.hour}:${e.minute}:${e.second}`;
						}
						break;
				}
			},
			calendar(param) {
				this.show = true;
				switch (param) {
					case 1:
						this.num = 1;
						break;
					case 2:
						this.num = 2;
						break;
				}
			},
		}

	}
</script>

<style lang="scss">
	.container {
		width: 100%;
		background-color: #F2F2F2;
		height: 100vh;

		.list {
			background-color: #fff;
			margin-top: 20rpx;
			width: 710rpx;
			margin-left: 20rpx;
			border-radius: 12rpx;

			.designation {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 110rpx;
					}

					&:nth-child(2) {
						color: #333333;
						width: 550rpx;
						text-align: right;
					}
				}
			}

			.numeration {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 110rpx;
					}

					&:nth-child(2) {
						color: #333333;
						width: 550rpx;
						text-align: right;
					}
				}
			}

			.address {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 110rpx;
					}

					&:nth-child(2) {
						color: #333333;
						width: 550rpx;
						text-align: right;
					}
				}
			}

			.type {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 110rpx;
					}

					&:nth-child(2) {
						color: #333333;
						width: 550rpx;
						text-align: right;
					}
				}
			}

			.galleryful {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					font-size: 26rpx;

					&:nth-child(1) {
						color: #666666;
						width: 200rpx;
					}

					&:nth-child(2) {
						color: #333333;
						width: 460rpx;
						text-align: right;
					}
				}
			}

			.remarks {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;
					}
				}

			}

			.time {
				width: 94%;
				margin-left: 3%;
				height: 180rpx;
				border-bottom: 1px solid #F2F2F2;

				.top {
					width: 100%;
					height: 90rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					text {
						font-size: 26rpx;

						&:nth-child(1) {
							color: #666666;
							width: 133rpx;
						}

						&:nth-child(2) {
							color: #333333;
							width: 440rpx;
							text-align: right;
						}
					}

					image {
						&:nth-child(3) {
							width: 30rpx;
							margin-left: 50rpx;
						}
					}
				}

				.bottom {
					width: 100%;
					height: 90rpx;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					text {
						font-size: 26rpx;

						&:nth-child(1) {
							color: #333333;
							width: 593rpx;
							text-align: right;
						}
					}

					image {
						&:nth-child(2) {
							margin-left: 30rpx;
							width: 30rpx;
						}
					}
				}
			}



			.event {
				width: 94%;
				margin-left: 3%;
				height: 90rpx;
				border-bottom: 1px solid #F2F2F2;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				text {
					&:nth-child(1) {
						color: #666666;
						font-size: 26rpx;
					}
				}

			}
		}

		.confirm {
			width: 100%;
			height: 200rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.verify {
				width: 200rpx;
				height: 60rpx;
				border-radius: 50rpx;
				text-align: center;
				line-height: 60rpx;
				background: linear-gradient(to right, #2C78FE, #32B0FF);
				color: #fff;
				font-size: 30rpx;
			}
		}
	}
</style>
